import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author CHENTAIWEN
 * @create 2022/10/18 11:20
 */
public class java8stream {

    public static void main(String[] args) {
        List<JavaStream> javaStreams = new ArrayList<>();
        JavaStream javaStream = new JavaStream();
        JavaStream javaStream1 = new JavaStream();
        JavaStream javaStream2 = new JavaStream();
        javaStream.setId("1");
        javaStream.setName("1");
        javaStream.setAddress("1213123123");
        javaStream.setAge(BigDecimal.valueOf(20));
        javaStreams.add(javaStream);
        javaStream1.setId("1");
        javaStream1.setName("1");
        javaStream1.setAge(BigDecimal.valueOf(20));
        javaStream1.setAddress("121312312333");
        javaStreams.add(javaStream1);
        javaStream2.setId("2");
        javaStream2.setName("2");
        javaStream2.setAddress("1213123123121");
        javaStream2.setAge(BigDecimal.valueOf(20));
        javaStreams.add(javaStream2);
        /**.map(JavaStream::getAge).reduce(BigDecimal.ZERO,BigDecimal::add)
         * .mapToInt().sum;
         * .mapToLong().sum;
         * .mapToDouble().sum;
         */
        BigDecimal sum = javaStreams.stream().map(i -> {
            JavaStream javaStream3 = new JavaStream();
            javaStream3.setId(i.getId());
            javaStream3.setName(i.getName());
            javaStream3.setAge(i.getAge());
            return javaStream3;
        }).distinct().collect(Collectors.toList()).stream().map(JavaStream::getAge).reduce(BigDecimal.ZERO, BigDecimal::add);

        System.out.println(sum);
    }


    @Data
    private static class JavaStream {
        private String id;
        private String name;
        private String address;
        private BigDecimal age;
    }
}

